//
//  BRUnpayView.m
//  BrezzeSaaS
//
//  Created by IOS on 2021/11/23.
//  Copyright © 2021 Brezze GWG. All rights reserved.
//

#import "BRUnpayView.h"

@implementation BRUnpayView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setUI];
    }
    return self;
}

- (void)setOrderType:(NSInteger)orderType {
    _orderType  = orderType;
    
    NSString *text = orderType == 3 ? Localized(@"home_underInvestigation") :Localized(@"home_unpaidOrder");
    self.statusLabel.text = text;
}


- (void)show {
    self.hidden = NO;
}

- (void)hidden {
    self.hidden = YES;
}

- (void)setIsUnpay:(BOOL)isUnpay {
    _isUnpay = isUnpay;
    
    _statusLabel.text = isUnpay ? Localized(@"home_unpaidOrder") :  Localized(@"home_underInvestigation");
}

#pragma mark - SET UI --
- (void)setUI {
    self.backgroundColor = UIColorClear;
    self.userInteractionEnabled = YES;
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.mj_w, self.mj_h)];
    view.backgroundColor = UIColor.whiteColor;
    view.layer.cornerRadius = 13;
    view.layer.masksToBounds = YES;
    view.userInteractionEnabled = YES;
    [self addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(14);
        make.right.offset(-14);
        make.bottom.offset(0);
        make.top.offset(0);
    }];
    
    UIView *viewContent = [[UIView alloc] init];
    viewContent.backgroundColor = UIColorClear;
    [view addSubview:viewContent];
    [viewContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.right.offset(0);
        make.bottom.offset(0);
        make.top.offset(0);
        make.height.mas_equalTo(52);
    }];
    
    UIImageView *image = [[UIImageView alloc] init];
    image.image = UIImageMake(@"arrow_right_gray6");
    [viewContent addSubview:image];
    [image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(6);
        make.height.mas_equalTo(10);
        make.centerY.offset(0);
        make.right.offset(-20);
    }];
    
   
    
    QMUILabel *statusLabel = [[QMUILabel alloc] init];
    statusLabel.text = Localized(@"home_unpaidOrder");
    statusLabel.textColor = UIColor.qd_titleTextColor;
    statusLabel.font = [UIFont fontB:17];
    statusLabel.numberOfLines = 2;
    statusLabel.textAlignment = NSTextAlignmentLeft;
    [viewContent addSubview:statusLabel];
    [statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(32);
        make.centerY.offset(0);
    }];
    _statusLabel = statusLabel;
    
    UIView *leftView = [[UIView alloc] init];
    leftView.backgroundColor = UIColorMakeWithHex(@"#FFC855");
    leftView.layer.cornerRadius = 4;
    leftView.layer.masksToBounds = YES;
    [viewContent addSubview:leftView];
    [leftView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(8);
        make.left.offset(14);
        make.centerY.offset(0);
    }];
    
    
}
- (void)createShadow {
    self.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.07].CGColor;
    self.layer.shadowOffset = CGSizeMake(0,5);
    self.layer.shadowOpacity = 1;
    self.layer.shadowRadius = 8;
}

@end


@interface BRRuleView ()
{
    UIView *_contentView;
    UIImageView *_rightImg;
    QMUILabel *_titleL;
    UIView *_line;
    QMUILabel *_contentLB;
    
    MASConstraint *_bottomMas;
}
@end

@implementation BRRuleView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}

- (void)show {
    self.hidden = NO;
}

- (void)hidden {
    self.hidden = YES;
}
#pragma mark -  func --
- (void)touchContent:(UITapGestureRecognizer *)tap {
    
    self.isOpen = !self.isOpen;
    
//    _line.hidden = !self.isOpen;
}

- (void)open {
    
    _rightImg.transform = CGAffineTransformMakeRotation(M_PI_2);
    if (_bottomMas) [_bottomMas uninstall];
    [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {

        _bottomMas = make.bottom.equalTo(_contentLB.mas_bottom).offset(16).priority(1000);
    }];
    [UIView animateWithDuration:0.3 animations:^{
        [self.superview layoutIfNeeded];
    }];
}

- (void)close {
    
    _rightImg.transform = CGAffineTransformMakeRotation(0);
    if (_bottomMas) [_bottomMas uninstall];
    
    [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {

        _bottomMas = make.bottom.equalTo(_rightImg).offset(4).priority(1000);
    }];
    [UIView animateWithDuration:0.3 animations:^{
        [self.superview layoutIfNeeded];
    }];
    
}

- (void)setIsOpen:(BOOL)isOpen {
    _isOpen = isOpen;
//    isOpen == YES ? [self open] : [self close];
}

- (void)setRuleStr:(NSString *)ruleStr {
    _ruleStr = ruleStr;
    _contentLB.text = ruleStr;
}


#pragma mark - SET UI --
- (void)setUI {
    
    _contentView = [[UIView alloc] init];
    _contentView.backgroundColor = UIColor.qd_backgroundColor3;
    _contentView.layer.cornerRadius = 10.;
    _contentView.layer.masksToBounds = YES;
    _contentView.userInteractionEnabled = YES;
    [self addSubview:_contentView];
    [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(0);
        make.left.offset(16);
        make.right.offset(-16);
        make.bottom.offset(0);
    }];
    
    _rightImg  = [[UIImageView alloc] init];
    _rightImg.hidden = YES;
    _rightImg.image = UIImageMake(@"arrow_right_gray44");
    [_contentView addSubview:_rightImg];
    [_rightImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(44);
        make.top.offset(4);
        make.right.offset(0);
    }];
    
    
    _titleL = [[QMUILabel alloc] init];
    _titleL.text = Localized(@"Station_pricePlan");
    _titleL.font = [UIFont br_fontB:17];
    _titleL.textAlignment = NSTextAlignmentLeft;
    _titleL.textColor = UIColor.qd_titleTextColor;
    [_contentView addSubview:_titleL];
    [_titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(40);
        make.right.offset(-16);
        make.centerY.equalTo(_rightImg);
    }];
    
    UIImageView *img = [[UIImageView alloc] initWithImage:UIImageMake(@"home_tag")];
    [_contentView addSubview:img];
    [img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(16);
        make.width.height.mas_equalTo(16);
        make.centerY.equalTo(_titleL);
    }];
    
    UIView *line = [[UIView alloc] init];
    line.backgroundColor = UIColor.qd_lineColor3;
    [_contentView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(16);
        make.right.offset(-16);
        make.top.offset(48);
        make.height.mas_equalTo(0.5);
    }];
    _line = line;
    line.hidden = YES;
    
    _contentLB = [[QMUILabel alloc] init];
    _contentLB.numberOfLines = 0;
    _contentLB.text = USERManager.rentRule;
    _contentLB.textAlignment = NSTextAlignmentLeft;
    _contentLB.font = [UIFont br_fontM:14];
    _contentLB.textColor = UIColor.qd_titleTextColor;
    [_contentView addSubview:_contentLB];
    [_contentLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(16);
        make.right.offset(-16);
        make.top.equalTo(line.mas_bottom).offset(0);
        make.bottom.offset(-16);//固定高度
    }];
    
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchContent:)];
//    [_contentView addGestureRecognizer:tap];
    
//    self.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.10].CGColor;
//    self.layer.shadowOffset = CGSizeMake(0,5);
//    self.layer.shadowRadius = 8;
//    self.layer.shadowOpacity = 1;
}


@end
